package com.study.demoservice.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author chenyeqing
 */
@WebFilter
@Slf4j
public class TimeCostFilter implements Filter {

    public TimeCostFilter() {
        log.info("TimeCostFilter 构造");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("开始计算接口耗时");
        long startTime = System.currentTimeMillis();
        filterChain.doFilter(servletRequest, servletResponse);
        long endTime = System.currentTimeMillis();
        long time = endTime - startTime;
        log.info("执行时间：{}ms", time);
    }

}
